package com.erms.lab.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.erms.common.annotation.Log;
import com.erms.common.enums.BusinessType;
import com.erms.lab.domain.SysCompetition;
import com.erms.lab.service.ISysCompetitionService;
import com.erms.common.core.controller.BaseController;
import com.erms.common.core.domain.AjaxResult;
import com.erms.common.utils.poi.ExcelUtil;
import com.erms.common.core.page.TableDataInfo;

/**
 * 承办竞赛情况Controller
 * 
 * @author guo
 * @date 2020-03-22
 */
@Controller
@RequestMapping("/lab/competition")
public class SysCompetitionController extends BaseController
{
    private String prefix = "lab/competition";

    @Autowired
    private ISysCompetitionService sysCompetitionService;

    @RequiresPermissions("lab:competition:view")
    @GetMapping()
    public String competition()
    {
        return prefix + "/competition";
    }

    /**
     * 查询承办竞赛情况列表
     */
    @RequiresPermissions("lab:competition:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SysCompetition sysCompetition)
    {
        startPage();
        List<SysCompetition> list = sysCompetitionService.selectSysCompetitionList(sysCompetition);
        return getDataTable(list);
    }

    /**
     * 导出承办竞赛情况列表
     */
    @RequiresPermissions("lab:competition:export")
    @Log(title = "承办竞赛情况", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SysCompetition sysCompetition)
    {
        List<SysCompetition> list = sysCompetitionService.selectSysCompetitionList(sysCompetition);
        ExcelUtil<SysCompetition> util = new ExcelUtil<SysCompetition>(SysCompetition.class);
        return util.exportExcel(list, "competition");
    }

    /**
     * 新增承办竞赛情况
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存承办竞赛情况
     */
    @RequiresPermissions("lab:competition:add")
    @Log(title = "承办竞赛情况", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(SysCompetition sysCompetition)
    {
        return toAjax(sysCompetitionService.insertSysCompetition(sysCompetition));
    }

    /**
     * 修改承办竞赛情况
     */
    @GetMapping("/edit/{comId}")
    public String edit(@PathVariable("comId") Long comId, ModelMap mmap)
    {
        SysCompetition sysCompetition = sysCompetitionService.selectSysCompetitionById(comId);
        mmap.put("sysCompetition", sysCompetition);
        return prefix + "/edit";
    }

    /**
     * 修改保存承办竞赛情况
     */
    @RequiresPermissions("lab:competition:edit")
    @Log(title = "承办竞赛情况", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(SysCompetition sysCompetition)
    {
        return toAjax(sysCompetitionService.updateSysCompetition(sysCompetition));
    }

    /**
     * 删除承办竞赛情况
     */
    @RequiresPermissions("lab:competition:remove")
    @Log(title = "承办竞赛情况", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(sysCompetitionService.deleteSysCompetitionByIds(ids));
    }
}
